package com.jxsm.page;

import java.util.List;

/**
 * Created by Administrator on 2016/10/30.
 */
public class Page<T> {
    private int pageSize;//每页显示的记录数；
    private long totalNumber;//总记录数
    private long pageNo;// 当前页
    private List<T> list;// 返回查找的对象的list集合；

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    //总共有多少页；
    public long getTotalPageNumber() {
        return Math.round(getTotalNumber()/getPageSize());
    }

    public long getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(long totalNumber) {
        this.totalNumber = totalNumber;
    }
//    返回当页前的
    public long getPageNo() {
        if(pageNo<0){
            pageNo=1;
        }
        if (pageNo>getTotalPageNumber()){
            pageNo=getTotalPageNumber();
        }
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    //判断是否有下一页；
    public boolean isHasNext(){
        if(getPageNo()<getTotalPageNumber()){
            return true;
        }
        return false;
    }
    //判断是否有上一页
    public boolean isHasPre(){
        if(getPageNo()>1){
            return true;
        }
        return false;
    }
    //下一页
    public long  getNextPage(){
        if(isHasNext()){
            return getPageNo()+1;
        }
        return  getPageNo();
    }

    //上一页
    public long  getPrePage(){
        if(isHasPre()){
            return getPageNo()-1;
        }
        return  getPageNo();
    }
}
